home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Library
/
RoseWare - Network Support Library.iso
/
apidev
/
spxcht.arc
/
RECSPX.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-01-04
|
4KB
|
120 lines
#include <stdio.h>
#include <nit.h>
#include "bill.h"
unsigned int Socket=0x5555;
long stats=0;
char *ReadData;
main(argc,argv)
int argc;
char *argv[];
{
int ccode, ConnectionID, i=0;
ECBStructure *PoolECB, *ConnectionECB;
SPXStructure *PoolSPX, *ConnectionSPX;
char far *farcharpointer;
char *data;
void ReceiveESRHandler();
ReadData = (char *)myalloc(1, 2);
IPXInitialize();
/* ********************************************************** */
if ((ccode = IPXOpenSocket(&Socket,0x00)) != 0) {
printf("A socket was not opened");
exit(-1);
}
/* ********************************************************** */
while (i++ != 5) {
if ((PoolECB = (ECBStructure *)myalloc(1, sizeof(ECBStructure))) == NULL ) {
printf("Out of memory trying to allocate for the PoolECB\n ");
exit(-1);
}
if ((PoolSPX = (SPXStructure *)myalloc(1, sizeof(SPXStructure))) == NULL ) {
printf("Out of memory trying to allocate for the PoolSPX\n ");
}
data = (char *)myalloc(1, 2);
farcharpointer = (char far *)ReceiveESRHandler;
PoolECB->ESRAddress = farcharpointer;
PoolECB->ECBSocket = Socket;
PoolECB->FragmentCount = 2;
farcharpointer = (char far *)PoolSPX;
PoolECB->FragmentDescriptor[0].Address = farcharpointer;
PoolECB->FragmentDescriptor[0].Size = sizeof(SPXStructure);
farcharpointer = (char far *)data;
PoolECB->FragmentDescriptor[1].Address = farcharpointer;
PoolECB->FragmentDescriptor[1].Size = 2;
PoolSPX->PacketType = (char)5;
PoolSPX->PacketLength = IntSwap( sizeof(SPXStructure));
SPXListenForSequencedPacket(PoolECB);
}
/* ************************************************************** */
if ((ConnectionECB = (ECBStructure *)myalloc(1, sizeof(ECBStructure))) == NULL) {
printf("Out of memory allocating for ConnectionECB\n ");
exit(-1);
}
if ((ConnectionSPX = (SPXStructure *)myalloc(1,sizeof(SPXStructure))) == NULL) {
printf("Out of memory allocating for ConnectionSPX\n");
exit(-1);
}
ConnectionSPX->PacketLength = IntSwap(sizeof(SPXStructure));
ConnectionSPX->PacketType = (char)5;
ConnectionECB->ECBSocket = Socket;
ConnectionECB->FragmentCount = 1;
farcharpointer = (char far *)ConnectionSPX;
ConnectionECB->FragmentDescriptor[0].Address = farcharpointer;
ConnectionECB->FragmentDescriptor[0].Size = sizeof(SPXStructure);
printf("\n\nWe are now in the mode of waiting for a connection....\n");
SPXListenForConnection((char)0, (char)0, ConnectionECB);
while (ConnectionECB->InUse) {
IPXRelinquishControl();
if (kbhit())
exit(0);
}
switch (ConnectionECB->CompletionCode) {
case 0x00:
memcpy((char *)&ConnectionID, (char *)ConnectionECB->IPXWorkspace, 2);
printf("Connection ID is: %x\n",ConnectionID);
break;
default:
printf("Connection was not established");
exit(-1);
break;
}
/* ****************************************************************** */
*ReadData = 0xFF;
while (!kbhit()) {
if (strcmp(*ReadData,(char)0xFF) != 0) {
if (strcmp(*ReadData,(char)0x1B) == 0)
exit(0);
printf("%c",*ReadData);
if (strcmp(*ReadData,(char)0x0D) == 0)
printf("\n");
*ReadData = 0xFF;
}
}
}
void ReceiveESR(ESR_ECB)
ECBStructure *ESR_ECB;
{
char far *farcharpointer;
farcharpointer = ESR_ECB->FragmentDescriptor[1].Address;
ReadData = (char *)farcharpointer;
stats++;
SPXListenForSequencedPacket(ESR_ECB);
}